package com.yxr.mobileplayer.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.text.format.Formatter;
import com.yxr.mobileplayer.R;
import com.yxr.mobileplayer.entity.MediaItem;
import com.yxr.mobileplayer.entity.ViewHolder;
import com.yxr.mobileplayer.tools.LArrayList;
import com.yxr.mobileplayer.tools.Utils;

public class NativeVideoPageAdapter extends BaseAdapter {
    protected Activity activity;
    private LArrayList<MediaItem> mediaItems;

    public NativeVideoPageAdapter(Activity activity, LArrayList<MediaItem> mediaItems) {
        this.activity = activity;
        this.mediaItems = mediaItems;
    }

    @Override
    public int getCount() {
        return mediaItems.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("Adapter","public class NativeVideoPageAdapter extends BaseAdapter ");
        ViewHolder viewHolder;
        if(convertView ==null){
            convertView = View.inflate(activity, R.layout.item_video_pager,null);
            viewHolder = new ViewHolder();
            viewHolder.setTv_name(convertView.findViewById(R.id.tv_name));
            viewHolder.setTv_duration(convertView.findViewById(R.id.tv_duration));
            viewHolder.setTv_size(convertView.findViewById(R.id.tv_size));
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MediaItem mediaItem = mediaItems.get(position);
        viewHolder.getTv_name().setText(mediaItem.getName());
        viewHolder.getTv_size().setText(Formatter.formatFileSize(activity, mediaItem.getSize()));
        viewHolder.getTv_duration().setText(new Utils().stringForTime((int) mediaItem.getDuration()));
        return convertView;
    }
}
